package com.xnfh.home.viewmodel

import com.xnfh.common.constant.KvKey
import com.xnfh.framework.base.BaseViewModel
import com.xnfh.framework.bean.HomeAppVersion
import com.xnfh.framework.bean.HomeBannerBean
import com.xnfh.framework.bean.HomeTongjiBean
import com.xnfh.framework.bean.RespStateData
import com.xnfh.framework.bean.WeatherDetailBean
import com.xnfh.framework.utils.KVUtil

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2024/1/2 14:02
 * @UpdateUser: ziheng
 * @UpdateDate: 2024/1/2 14:02
 * @UpdateRemark: 更新说明
 */
class HomeViewModel: BaseViewModel() {

    private val viewModelRes = HomeViewModelRes()
    val appVersionBean = RespStateData<HomeAppVersion>()
    val bannerBean = RespStateData<List<HomeBannerBean>>()
    val tjBean = RespStateData<HomeTongjiBean>()
    val weatherRes = RespStateData<WeatherDetailBean>()
    val noReadNum = RespStateData<Int>()

    /**
     * 获取app是否有更新
     */
    fun requestAppVersion() = launch {
        viewModelRes.requestAppVersion(appVersionBean)
    }

    /**
     * 获取今日头条信息
     */
    fun requestTodayMessage() = launch {
        viewModelRes.requestHomeBanner(bannerBean)
    }

    /**
     * 获取服务在线（统计柱形图）
     */
    fun requestTj() = launch {
        viewModelRes.requestTj(tjBean)
    }

    /**
     * 天气状态
     */
    fun requestWeather() = launch {
        val locationInfo = KVUtil.getString(KvKey.LOCATION_INFO)
        viewModelRes.requestWeather(locationInfo.toString(),weatherRes)
    }

    /**
     * 获取首页未读数量
     */
    fun requestNoReadNum() = launch {
        viewModelRes.requestNoReadNum(noReadNum)
    }

}